package com.mlz.mlzmall.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.mlz.mlzmall.R;
import com.mlz.mlzmall.bean.CartConfirm;
import com.mlz.mlzmall.bean.DefaultAddressInfo;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.text.DecimalFormat;

/**
 * describe :
 * Created by FUYING on 2016/5/26.
 * PackageName com.mlz.mall.ui.adapter.base.
 * ProjectName mlzMall v2.0.
 */
public class ConfirmOrderAdapter extends BaseAdapter {
    // 存放提交订单数据
    private CartConfirm.Data data;
    // 存放地址数据
    private DefaultAddressInfo addressData;
    // 上下文
    private Context context;
    private int resource;
    // 用于下载网路图片、定义参数
    private DisplayImageOptions options;
    // 新建静态实例对象
    private ImageLoader imageLoader = ImageLoader.getInstance();

    public ConfirmOrderAdapter(Context context, int resource, CartConfirm.Data data) {
        this.context = context;
        this.resource = resource;
        this.data = data;
        // 设置选项

    }

    @Override
    public int getCount() {
        if (data.getProducts() == null)
            return 0;
        return data.getProducts().size();
    }

    @Override
    public Object getItem(int position) {
        return data.getProducts().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder mViewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(resource, null);
            mViewHolder = new ViewHolder();
            mViewHolder.imageProduct = (ImageView) convertView.findViewById(R.id.imageProductConfirmOrder);
            mViewHolder.tvProductName = (TextView) convertView.findViewById(R.id.tvProductNameConfirmOrder);
            mViewHolder.tvQuantity = (TextView) convertView.findViewById(R.id.tvQuantityPurchasedConfirmOrder);
            mViewHolder.ivTaxConfirmOrder = (TextView) convertView.findViewById(R.id.ivTaxConfirmOrder);
            mViewHolder.tvPrice = (TextView) convertView.findViewById(R.id.tvPriceConfirmOrder);
            mViewHolder.ivTaxRate = (TextView) convertView.findViewById(R.id.ivTaxConfirmOrder);

            convertView.setTag(mViewHolder);
        } else {
            mViewHolder = (ViewHolder) convertView.getTag();
        }

        DecimalFormat df = new DecimalFormat("0.00 ");//使价格后保留两位小数
        // 获取数据
        CartConfirm.Data.Product product = data.getProducts().get(position);
        // 订单数据
        //产品名称
        mViewHolder.tvProductName.setText(product.getName().toString());
        // 商品的图片
        imageLoader.displayImage(product.getImage(), mViewHolder.imageProduct, options);
        // 该件产品的数量
        mViewHolder.tvQuantity.setText(String.valueOf(product.getQuantity()));
        // 该件产品的价格
        mViewHolder.tvPrice.setText(String.valueOf(df.format(product.getPrice())));
        // 商品税率
        mViewHolder.ivTaxConfirmOrder.setText(String.valueOf(df.format(product.getTariffRates() * 100) + "%"));

        // 海外仓库显示: 税率
        if (product.getWarehouse().equals("NSC")) {
            //   mViewHolder.LLayoutTax.setVisibility(View.VISIBLE);
        }
        return convertView;
    }


    class ViewHolder {
        ImageView imageProduct;
        TextView tvProductName;
        TextView tvQuantity;
        TextView tvPrice;
        TextView ivTaxRate;
        TextView ivTaxConfirmOrder;


    }

    //隐藏实名认证布局


}
